﻿using System;
using System.Web;
using ErrorDumper.Filtering;

namespace ErrorDumper.Web.Filters {
    public class HttpExceptionFilter : ExceptionFilterBase {

        public int HttpCode { get; protected set; }
        public ExceptionHandlingLevel Level { get; protected set; }

        public HttpExceptionFilter(int httpCode, ExceptionHandlingLevel level) {
            HttpCode = httpCode;
            Level = level;
        }

        public override ExceptionHandlingLevel? GetLevel(
            ExceptionPropertyCollection properties, Exception exception) {
            var httpException = exception as HttpException;
            return httpException != null && httpException.GetHttpCode() == HttpCode
                ? (ExceptionHandlingLevel?)Level
                : null;
        }
    }
}